package net.hn.hnms.biz.energy.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.energy.domain.WaterSupplyCompany;
import net.hn.hnms.biz.energy.request.WaterSupplyCompanyReq;
import net.hn.hnms.biz.energy.service.WaterSupplyCompanyService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "供水单位模块", tags = {"供水单位设置"})
@RestController
@RequestMapping("/water/supply/company")
public class WaterSupplyCompanyController extends BaseController {

    @Autowired
    private WaterSupplyCompanyService waterSupplyCompanyService;

    /**
     * 新增供水单位
     */
    @ApiOperation("新增供水单位")
    @SaCheckPermission("water:supply:add")
    @PostMapping("/add")
    @Log(title = "新增供水单位", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody WaterSupplyCompanyReq waterSupplyCompanyReq) {
        return toAjax(waterSupplyCompanyService.insert(waterSupplyCompanyReq));
    }

    /**
     * 删除供水单位
     */
    @ApiOperation("删除供水单位")
    @SaCheckPermission("water:supply:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除供水单位", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        waterSupplyCompanyService.updateDeleteByIds(idList);
        return R.ok();
    }

    /**
     * 更新供水单位
     */
    @ApiOperation("更新供水单位")
    @SaCheckPermission("water:supply:update")
    @PostMapping("/update")
    @Log(title = "更新供水单位", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody WaterSupplyCompanyReq waterSupplyCompanyReq) {
        waterSupplyCompanyService.updateById(waterSupplyCompanyReq);
        return R.ok();
    }

    /**
     * 获取供水单位详情
     */
    @ApiOperation("获取供水单位详情")
//    @SaCheckPermission("dispatch:keepwatch:detail")
    @GetMapping("/{id}")
    public R<WaterSupplyCompany> detail(@PathVariable("id") String id) {
        return R.ok(waterSupplyCompanyService.selectDetailById(id));
    }

    /**
     * 获取供水单位列表
     */
    @ApiOperation("获取供水单位列表")
//    @SaCheckPermission("plan:drivage:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<WaterSupplyCompany>> page(WaterSupplyCompanyReq planDrivage, PageQuery pageQuery) {
        return R.ok(waterSupplyCompanyService.selectPageList(planDrivage, pageQuery));
    }

    /**
     * 获取供水单位列表
     */
    @ApiOperation("获取供水单位列表")
//    @SaCheckPermission("plan:mining:list")
    @GetMapping("/list")
    @AutoSetMineCode
    public R<List<WaterSupplyCompany>> list(WaterSupplyCompanyReq waterSupplyCompanyReq) {
        return R.ok(waterSupplyCompanyService.selectList(waterSupplyCompanyReq));
    }



}
